using Abp.Dependency;
using Abp.Events.Bus.Handlers;
using Abp.Threading;
using Vecen.BangChuang.BangChuang.Common;
using Vecen.BangChuang.BangChuang.DomainServices.Common;
using Vecen.BangChuang.BangChuang.DomainServices.EventHandlers.EventDatas;

namespace Vecen.BangChuang.BangChuang.DomainServices.EventHandlers
{
    public class OrderSavedEventHandler : IEventHandler<OrderSavedEventData>, ITransientDependency
    {
        private readonly CounterDomainService _counterDomainService;

        public OrderSavedEventHandler(CounterDomainService counterDomainService)
        {
            _counterDomainService = counterDomainService;
        }

        public void HandleEvent(OrderSavedEventData eventData)
        {
            AsyncHelper.RunSync(
                () => _counterDomainService.RecordAsync(CounterType.Product.Saled, eventData.ProductId));
        }
    }
}